package com.ds.infrastructure.hyperspace.container.internal.operator;

import org.springframework.util.StringUtils;

/**
 * usage eg:
 *  [REMOVE_FIRST_SUBSTRING, delimiter]
 * @author  Weishaoying
 */
public class StringRemoveOperator extends AbstractOperator {

    private static final int AGRS_LENGTH = 1;

    @Override
    public String compute(String inputValue, String[] args) {
        if (StringUtils.isEmpty(inputValue) || args == null) {
            return null;
        }
        int firstIndex = inputValue.indexOf(args[0]);
        if (firstIndex != -1) {
            return inputValue.substring(0, firstIndex);
        }
        return inputValue;
    }

    @Override
    public String getOperatorName() {
        return "REMOVE_FIRST_SUBSTRING";
    }

    @Override
    public int getOperatorArgsLength() {
        return AGRS_LENGTH;
    }
}
